#!/bin/bash
#source ./var
source ./var
Lock_file(){
#    cd $dir
    echoRed "锁定关键系统文件，会导致锁定的文件不能进行写操作。如果需要写入，进行解锁文件就ok了"
    chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow

    #+a表示该文件只能增加记录
    chattr +a /var/log/dmesg /var/log/cron /var/log/lastlog /var/log/messages /var/log/secure /var/log/wtmp
    lsattr /etc/passwd /etc/shadow /etc/group /etc/gshadow /var/log/messages |egrep "(i|a)" &&  echoYellow "文件已锁定" || echoRed "文件未锁定"
#rm -rf $dir
}
UnLock_file(){
#    cd $dir
    echoRed "即将解锁相关文件"
    chattr -i /etc/passwd /etc/shadow /etc/group /etc/gshadow
    chattr -a /var/log/dmesg /var/log/cron /var/log/lastlog /var/log/messages /var/log/secure /var/log/wtmp
    lsattr /etc/passwd /etc/shadow /etc/group /etc/gshadow |grep "i" &&  echoGreen "文件已锁定" || echoYellow "文件未锁定"
#rm -rf $dir
}
